class AddMeds extends StatefulWidget{
  // ignore: prefer_const_constructors_in_immutables
  AddMeds({Key? key}) : super(key: key);

  @override
  _AddMeds createState() => _AddMeds();

}

class _AddMeds extends State<AddMeds> {

  final List<Widget> _cardList = [];





  void _addCardWidget() {
    setState(() {
      _cardList.add(_card());
    });
  }

  Widget _card(){
    return Container(

        padding: const EdgeInsets.fromLTRB(20, 20, 20, 20),
        margin: const EdgeInsets.fromLTRB(8, 0, 8, 8),
        decoration: BoxDecoration(
          color: Colors.amber,
          borderRadius: BorderRadius.circular(16.0),
        ),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          crossAxisAlignment: CrossAxisAlignment.center,
          // ignore: prefer_const_literals_to_create_immutables
          children: <Widget>[
            Text(
              'name',
              style: const TextStyle(
                color: Colors.white,
                fontSize: 24.0,
                fontWeight: FontWeight.w600,
              ),
            ),
            Text(
              "x",
              style: const TextStyle(
                color: Colors.white,
                fontSize: 24.0,
                fontWeight: FontWeight.w600,
              ),
            ),
            Text(
              'time',
              style: const TextStyle(
                color: Colors.white,
                fontSize: 24.0,
                fontWeight: FontWeight.bold,
              ),
            ),
          ],
        ),
      

    );

  }




  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        // Here we take the value from the MyHomePage object that was created by
        // the App.build method, and use it to set our appbar title.
        backgroundColor: Palette.primaryColor,
        title: Text("Add Widget Dynamically"),
      ),
      body: Column(
        children: [
          ListView(

          ),
          ListView.builder(
          itemCount: _cardList.length,
            itemBuilder: (context,index){
          return _cardList[index];
        }),

        ],
        
      ),
      floatingActionButton: FloatingActionButton(
        onPressed:
        _addCardWidget,
        tooltip: 'Add',
        child: Icon(Icons.add),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }

  
}